import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/login.vue'
import Home from '../components/home.vue'
import Welcome from '../components/welcome.vue'
import User from '../components/User/users.vue'
import Rights from '../components/power/rights.vue'
import Roles from '../components/power/roles.vue'
import Cate from '../components/goods/Cate.vue'
import 'element-ui/lib/theme-chalk/index.css'

Vue.use(VueRouter)

const routes = [
  { path: '/',redirect: '/login' },
  { path: '/login', component: Login },
  { path: '/home', redirect:'/welcome',
  component: Home ,children:[
    {path:'/welcome',component:Welcome},
    {path:'/users',component:User},
    {path:'/rights',component:Rights},
    {path:'/roles',component:Roles},
    {path:'/categories',component:Cate},
]},

]

const router = new VueRouter({
  routes
})

router.beforeEach((to,from,next)=>{
  if(to.path==='/login') return next()
  const tokens=window.sessionStorage.getItem('token')
  if(!tokens) return next('/login')
  next()
})

export default router
